﻿using System;
using System.Windows.Forms;
using System.Xml;

namespace RibbonEditor.Forms.Templates
{
    public partial class TemplateSelectionDialog : Form
    {
        public string SelectedTemplate { get; set; }

        public TemplateSelectionDialog(XmlNode templates)
        {
            InitializeComponent();
            this.FillList(templates);
        }

        private void FillList(XmlNode templates)
        {
            this.cboTemplatesList.Items.Clear();

            foreach (XmlNode templateNode in templates.ChildNodes)
            {
                this.cboTemplatesList.Items.Add(templateNode.Attributes["Id"].Value);
            }
        }

        private void btnTemplateSelectionValidate_Click(object sender, EventArgs e)
        {
            if (this.cboTemplatesList.SelectedItem == null)
            {
                MessageBox.Show(this, "Please select a template in the list", "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                this.SelectedTemplate = this.cboTemplatesList.SelectedItem.ToString();

                this.DialogResult = DialogResult.OK;
                this.Close();
            }
        }

        private void btnTemplateSelectionCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
